import { regionData } from "element-china-area-data";

export default {
  codeToTextArray(code) {
    if (code == null || code.length < 6) {
      return []
    }
    const proCode = code.substr(0, 2) + "0000";
    const cityCode = code.substr(0, 4) + "00";
    const proIndex = regionData.findIndex((val, index) => {
      return val.value == proCode;
    });
    const cityIndex = regionData[proIndex].children.findIndex(
      (val, index) => {
        return val.value == cityCode;
      }
    );
    const areaIndex = regionData[proIndex].children[
      cityIndex
    ].children.findIndex((val, index) => {
      return val.value == code;
    });
    let labelArr = [
      regionData[proIndex].label,
      regionData[proIndex].children[cityIndex].label,
      regionData[proIndex].children[cityIndex].children[areaIndex].label,
    ];
    return labelArr;
  }
}